<template>
	<view class="cart-container" v-if="cart.length !== 0">
		<!-- 收获地址区域 -->
		<my-address></my-address>
		<view class="cart-title">
			<!-- left -->
			<uni-icons type="shop" size="18"></uni-icons>
			<!-- right -->
			<text class="cart-title-text"> 购物车</text>
		</view>
		<!-- 购物车商品信息 -->
		<uni-swipe-action>
			<view class="" v-for="(item,i) in cart" :key="i">
				<uni-swipe-action-item :right-options="Options" @click="swipeItemHandler(item)">
					<my-cart-goods :goods="item" @RadioChange='radioChangeHandler' @NumChange='numChangeHandler'></my-cart-goods>
				</uni-swipe-action-item>
			</view>
		</uni-swipe-action>
		<!-- 结算组件 -->
		<my-settle></my-settle>
		
		
	</view>
	<!-- 购物车空空如也区域 -->
	<view class="empty-cart" v-else>
		<image src="/static/cart_empty@2x.png" class="empty-iamge" mode=""></image>
		<text>空空如也~</text>
	</view>
</template>

<script>
	import badgeMix from "@/mixins/tabbar-badge.js"
	import {mapState,mapMutations} from 'vuex'
	export default {
		data() {
			return {
				Options: [{
					text: '删除', // 显示的文本内容
					style: {
						backgroundColor: '#C00000' // 按钮的背景颜色
					}
				}]
			}
		},
		computed : {
			...mapState('m_cart',['cart'])
		},
		mixins:[badgeMix],
		methods:{
			...mapMutations('m_cart',['updateGoodsStates','updateGoodsCount','removeGoodsItem']),
			radioChangeHandler(e){
				this.updateGoodsStates(e)
			},
			numChangeHandler(e){
				this.updateGoodsCount(e)
			},
			swipeItemHandler(goods){
				this.removeGoodsItem(goods)
			}
		}
	}
</script>

<style lang="scss" scoped>
.cart-container{
	padding-bottom: 50px;
}
.cart-title{
	height: 40px;
	display: flex;
	align-items: center;
	padding-left: 5px;
	border-bottom: 1px solid #efefef;
	.cart-title-text{
		margin-left: 10px;
		
	}
	
}
.empty-cart{
	display: flex;
	flex-direction: column;
	align-items: center;
	padding-top: 150px;
	.empty-iamge{
		height: 100px;
		width: 100px;
	}
	text{
		font-size: 14px;
		color: gray;
		margin-top: 10px;
	}
}
</style>
